<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:py="http://genshi.edgewall.org/" py:strip="">
  <xi:include href="layout.html"/>
  <xi:include href="macros.html"/>
  <xi:include href="discussion-macros.html"/>

  <?python
    from trac.util.datefmt import format_datetime, pretty_timedelta
    from multiproject.core.configuration import conf
  ?>

  <head>

    <title>Message List</title>
    <script type="text/javascript">
      $(document).ready(function() {
        $("#content").find("h1,h2,h3,h4,h5,h6").addAnchor("Link to this section");
      });

      $(document).ready(function() {
          $("#showrows option[name='${discussion.paginator.max_per_page}']").attr('selected', 'selected');
      });
    </script>
    <link rel="stylesheet" type="text/css" href="${href('/chrome/multiproject/css/jquery-ui.css')}" />
    <script type="text/javascript" src="${href('/chrome/multiproject/js/jquery-ui.js')}"></script>
  </head>

  <body>

    <xi:include href="discussion-header.html"/>

    <div id="content" class="discussion searchable">
      <div id="${discussion.mode}" class="${discussion.mode}">

        <div class="breadcrumb">
          <a href="${href.discussion()}">
            <span>Forum List</span>
          </a>
          <span> &gt; </span>
          <a href="${href.discussion('forum', discussion.forum.id)}">
            <span>${discussion.forum.subject}</span>
          </a>
        </div>

        <div id="topic">
          <h1 class="subpage_title">${discussion.topic.subject}</h1>
        </div>

        <div class="buttons">
          <a py:if="(discussion.forum.name != conf.news_forum_name and 'DISCUSSION_APPEND' in perm) or (discussion.forum.name == conf.news_forum_name and 'DISCUSSION_ANNOUNCEAPPEND' in perm)" style="${'display: none;' if 'locked' in discussion.topic.status else ''}"
          href="${href.discussion('topic', discussion.topic.id)}?discussion_action=quote#addmessage" class="primaryButton" id="reply">Reply to Thread</a>

	        <div py:if="discussion.authemail" id="subscribe_button" style="float:right;margin-right:10px;">
            <py:choose>
              <py:when test="discussion.authname in discussion.topic.subscribers or discussion.authemail in discussion.topic.subscribers">
                <input type="submit" value="Unsubscribe" id="subscribe"
                  onclick="subscribe_user('${req.href.discussion('ajax', 'topic',
                  discussion.topic.id)}', '${discussion.authname}', 'False')" class="secondaryButton" />
              </py:when>
              <py:otherwise>
                <input type="submit" value="Subscribe" id="subscribe"
                      onclick="subscribe_user('${req.href.discussion('ajax', 'topic',
                      discussion.topic.id)}', '${discussion.authname}', 'True')" class="secondaryButton" />
              </py:otherwise>
            </py:choose>
	        </div>
        </div>

        <div py:if="'DISCUSSION_MODERATE' in perm and discussion.moderator" class="buttons">
          <form id="deletetopic" method="post" action="${href.discussion('topic', discussion.topic.id)}">
            <div>
              <input type="submit" name="deletetopic" value="Delete Topic"
                onclick="return confirm('Do you really want to delete this topic?')"
                style="width: 124px;" class="primaryButton"/>
              <input type="hidden" name="discussion_action" value="delete"/>
            </div>
          </form>
          <form id="movetopic" method="post" action="${href.discussion('topic', discussion.topic.id)}" style="margin-right:10px;">
            <div >
              <input type="submit" name="movetopic" value="Move Topic" style="width: 105px;" class="secondaryButton"/>
              <input type="hidden" name="discussion_action" value="move"/>
            </div>
          </form>
        </div>

        <div id="settingsbar">
          <form method="get" action="${href.discussion()}/topic/${discussion.topic.id}" id="showsettings" name="showsettings">
            <div id="sortingbox">
              <div class = "buttons forumSortBtn">
                <input type="submit" value="Go" id="go" class="primaryButton"/>
              </div>
              <label id="sorttxt" for="showrows">
                <span id="showrowstitle">Show rows:</span>
              </label>
              <select class="selectMenu" id="showrows" name="rowsperpage">
                <option py:for="num in [10,20,50,100,150,200]" name="${num}" value="${num}">${num}</option>
             </select>
            </div>
          </form>
        </div>

        ${display_discussion(discussion, href.discussion('topic', discussion.topic.id))}

      </div>
    </div>

    <xi:include href="rss_feed.html"/>

    <script type="text/javascript">
      var subsfield = $("#unregistered_subscribers");
      var requester = function (request, response) {
        // Show loader class until response is shown
        subsfield.addClass('loading');
        var keyword = subsfield.val();
        $.getJSON("${req.base_path}/userautocomplete", {q:keyword, fields:'username'}, function(data){
          var ulist = [];
          $.each(data, function(key, user) {
              ulist.push(user.username);
          });
          response(ulist);
          subsfield.removeClass('loading');
        });
      };
      subsfield.autocomplete({source:requester, minLength:3});
    </script>
  </body>
</html>
